<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'save_user.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="<c:url value='/resources/js/jquery-1.8.3.min.js'/>"></script>

  </head>
  
  <body>
    <div id="save-user-box">
	    <form id="userForm" action="<c:url value='/user/save.user'/>">
	    	<div id="username">
	    		<span>用户名:</span>
	    		<input type="text" name="username"/>
	    	</div>
	    	<div id="password">
	    		<span>年龄:</span>
	    		<input type="text" name="age">
	    	</div>
	    	<a id="btn" href="javascript:;">提交</a>
	    </form>
    </div>
    <script type="text/javascript">
    	$(document).ready(function(){
    		$("#btn").on("click",function(){
    			var param=$("#userForm").serialize();
    			$.ajax({
    				url:"<c:url value='/user/save.user'/>",
    				data:param,
    				success:function(e){
    					if(e!=null && e=="success")
    						alert("保存成功");
    					location.href="<c:url value='/user/get_users.htm'/>";
    				}
    			});
    		});
    	});
    </script>
  </body>
</html>
